﻿package kit4j.view.cs.swing.component;

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import kit4j.view.cs.FontSize;

/**
 * 字体尺寸列表的单元格绘制组件。
 * 
 * @author MiniKnife
 * 
 */
public class JFontSizeListCellRenderer extends JLabel implements ListCellRenderer {

	private static final long serialVersionUID = 1L;

	public JFontSizeListCellRenderer() {
		super();
	}

	@Override
	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
			boolean cellHasFocus) {
		if (value != null) {
			FontSize fs = (FontSize) value;
			setText(fs.getName());
		}

		if (isSelected) {
			setBackground(list.getSelectionBackground());
			setForeground(list.getSelectionForeground());
		} else {
			setBackground(list.getBackground());
			setForeground(list.getForeground());
		}
		setEnabled(list.isEnabled());
		setFont(list.getFont());
		setOpaque(true);

		return this;
	}

}
